#include <REGX52.H>
#include "Timer0.h"
#include "Delay.h"
#include "LCD1602.h"

unsigned char Sec,Min,Hour;
void main(void)
{
	LCD_Init();
	Timer0_Init();
	LCD_ShowString(1,1,"Clock:");
	LCD_ShowString(2,1,"  :  :");
	while (1)
	{
		LCD_ShowNum(2,1,Hour,2);
		LCD_ShowNum(2,4,Min,2);
		LCD_ShowNum(2,7,Sec,2);
	}
}

void Timer0_Routine(void) interrupt 1
{
	static unsigned int T0Count = 0;
	//TH0寄存器
	TH0 = 0XFC;
	//TL0寄存器
	TL0 = 0X17 + 1;
	T0Count++;
	if (T0Count >= 1000)
	{
		Sec++;
		if (Sec >= 60)
		{
			Sec = 0;
			Min++;
			if (Min >= 60)
			{
				Min = 0;
				Hour++;
				if (Hour >= 24)
				{
					Hour = 0;
				}
			}
		}
		T0Count = 0;
	}
}
